<?php include $this->admin_tpl('meta', 'admin');?>
<link rel="stylesheet" type="text/css" href="<?php echo STATIC_URL;?>plugin/swiper/css/swiper.min.css" />
<link rel="stylesheet" type="text/css" href="<?php echo STATIC_URL;?>admin/yzm_admin/css/yzm.admin.home.css" />
<title>我的桌面</title>
<meta name="referrer" content="no-referrer" />
<style>
.btn{border:1px solid #1e9fff;padding:3px 8px;height:25px;line-height:25px;color:#1e9fff;white-space:nowrap;display:inline-block;margin-left:5px;}
.btn:hover{decoration:none;background:#1e9fff;color:#fff;}
.label{margin-left:3px;height:20px;line-height:20px;}
</style>
</head>
<body>
<div class="page-container" style="margin:0;padding:0 10px;">
	<div class="col-md-6 mt-20">
		<div class="panel panel-default" style="height:253px;position:relative;">
		<div class="panel-header">发货统计</div>
			<div class="panel-body yzm-box-container" style="margin-top:-10px;">
				<div id="loading" style="height:200px;line-height:200px;text-align:center;">加载中...</div>
				<div id="container" style="height:210px;">
				</div>
			</div>
			<span class="f-r" style="position:absolute;top:3px;right:10px;">
				<span class="label label-success radius" onclick="echart(1)" style="cursor:pointer">刷新</span>
				 <span class="select-box inline" style="background:#fff;">
					<select name="shop_id" class="select select_trend" style="width:100px;">
						<option value="0">所有店铺</option>
						<?php
						$shop_ids = shop_ids();
							foreach($shop_ids as $val){
								$str = '';
								echo '<option value="'.$val['shop_id'].'" '.$str.'>'.$val['shop_name'].'</option>';
							}
						?>
					</select>
				</span>
				
				 <span class="select-box inline" style="background:#fff;">
					<select name="days" class="select select_trend" style="width:50px;">
						<option value="7">7天</option>
						<option value="15">15天</option>
						<option value="30">30天</option>
					</select>
				</span>
				<input name="is_ys_checkbox" type="checkbox" checked> 佑晟
			</span>
		</div>
	</div>
	
	<div class="col-md-6 mt-20">
		<div class="panel panel-default" style="height:253px;position:relative;">
			<div class="panel-header">订单流入统计</div>
			<div class="panel-body yzm-box-container" style="margin-top:-10px;">
				<div id="loading2" style="height:200px;line-height:200px;text-align:center;">加载中...</div>
				<div id="container2" style="height:210px;">
				</div>
			</div>
			<span class="f-r" style="position:absolute;top:3px;right:10px;">
				 <span class="label label-success radius" onclick="echart2()" style="cursor:pointer">刷新</span>
				 <span class="select-box inline" style="background:#fff;">
					<select name="shop_id_orders" class="select select_orders" style="width:100px;">
						<option value="0">所有店铺</option>
						<?php
						$shop_ids = shop_ids();
							foreach($shop_ids as $val){
								$str = '';
								echo '<option value="'.$val['shop_id'].'" '.$str.'>'.$val['shop_name'].'</option>';
							}
						?>
					</select>
				</span>
				<input name="is_ys_checkbox_orders" type="checkbox" checked> 佑晟
			</span>
		</div>
	</div>
	
	<div class="col-md-6" style="padding:0;">
		<div class="col-md-6 mt-20">
			<div class="panel panel-default" style="height:810px;">
				<div class="panel-header">库存信息</div>
				<div class="panel-body">
					<table class="table table-border table-bordered table-hover">
					  <tr class="text-c">
						<th>品牌</th>
						<th>库存</th>
					  </tr>
					<?php $total=0; foreach($ys_inventorys_info as $v){ $total+=$v['qty'];?>
					  <tr>
						<td><?php echo $v['brand']?></td>
						<td><?php echo $v['qty']?></td>
					  </tr>
					<?php } ?>
					<tr>
						<td class="text-r"><strong>佑晟库存总计：</strong></td>
						<td><strong><?php echo $total;?></strong></td>
					</tr>
					<?php $total=0; foreach($ts_inventorys_info as $v){ $total+=$v['qty'];?>
					  <tr>
						<td><?php echo $v['brand']?></td>
						<td><?php echo $v['qty']?></td>
					  </tr>
					<?php } ?>
					<tr>
						<td class="text-r"><strong>唐狮库存总计：</strong></td>
						<td><strong><?php echo $total;?></strong></td>
					</tr>
					<?php foreach($inventorys_info as $v){?>
					  <tr>
						<td><?php echo $v['brand']?></td>
						<td><?php echo $v['qty']?></td>
					  </tr>
					<?php } ?>
					</table>
				</div>
			</div>
		</div>
		
		<div class="col-md-6 mt-20">
			<div class="panel panel-default" style="height:810px;">
				<div class="panel-header" style="height:20px;"><span class="f-l">发货件数信息</span><span class="f-r c-red"><?php echo $orders_info_title;?></span></div>
				<div class="panel-body">
					<table class="table table-border table-bordered table-hover">
					  <tr class="text-c">
						<th>店铺</th>
						<th>发货件数</th>
						<th>补货件数</th>
					  </tr>
					<?php $total_ys=0;$bh_total_ys=0; foreach($ys_orders_info as $v){ $total_ys+=$v['qty'];$bh_total_ys +=$v['bh_qty'];?>
					  <tr>
						<td><?php echo $v['shop_name']?></td>
						<td><?php echo $v['qty']?></td>
						<td><?php echo $v['bh_qty']?></td>
					  </tr>
					<?php } ?>
					<tr>
						<td class="text-r"><strong>佑晟总计：</strong></td>
						<td><strong><?php echo $total_ys;?></strong></td>
						<td><strong><?php echo $bh_total_ys;?></strong></td>
					</tr>
					<?php $total_fp=0;$bh_total_fp=0; foreach($fp_orders_info as $v){ $total_fp+=$v['qty'];$bh_total_fp +=$v['bh_qty'];?>
					  <tr>
						<td><?php echo $v['shop_name']?></td>
						<td><?php echo $v['qty']?></td>
						<td><?php echo $v['bh_qty']?></td>
					  </tr>
					<?php } ?>
					<tr>
						<td class="text-r"><strong>法派总计：</strong></td>
						<td><strong><?php echo $total_fp;?></strong></td>
						<td><strong><?php echo $bh_total_fp;?></strong></td>
					</tr>
					<?php $total = $total_ys+$total_fp;$bh_total=$bh_total_ys+$bh_total_fp;foreach($orders_info as $v){$total+=$v['qty'];$bh_total+=$v['bh_qty'];?>
					  <tr>
						<td><?php echo $v['shop_name']?></td>
						<td><?php echo $v['qty']?></td>
						<td><?php echo $v['bh_qty']?></td>
					  </tr>
					<?php } ?>
					  <tr>
						<td class="text-r"><strong>全部总计：</strong></td>
						<td><strong><?php echo $total;?></strong></td>
						<td><strong><?php echo $bh_total;?></strong></td>
					  </tr>
					</table>
				</div>
			</div>
		</div>

		<div class="col-md-12 mt-20" style="display:none;">
			<div class="panel panel-default" style="height:445px;position:relative;padding:0;margin-bottom:20px;">
				<div class="panel-header" style="height:20px;"><span class="f-l">缺货统计</span></div>
				<div class="panel-body" style="padding:0;">
	  
					<div class="" style="padding:10px;">
						<div id="loading_suggest" style="height:200px;line-height:200px;text-align:center;">加载中...</div>
						<div id="container_suggest" style="padding:5px;padding-bottom:0;"></div>
					</div>
	  
					<span class="f-r" style="position:absolute;top:3px;right:10px;">
					<span class="label label-success radius" onclick="suggest()" style="cursor:pointer">刷新</span>
					</span>
					
				</div>
			</div>
		</div>
	
	</div>
	<div class="col-md-6 mt-20" style="">
		<div class="panel panel-default" style="height:810px;position:relative;padding:0;margin-bottom:20px;">
			<div class="panel-header" style="height:20px;"><span class="f-l">销量榜单</span><span class="f-l c-red">（昨日销量）</span></div>
			<div class="panel-body" style="padding:0;">


				<div class="" style="">
					<div id="loading_sale" style="height:200px;line-height:200px;text-align:center;">加载中...</div>
					<div id="container_sale" style="padding:5px;padding-bottom:0;">
					</div>
					<div style="text-align:center;margin-top:3px;" id="page">
						<a href="javascript:page_prev()" title="上一页" class="btn">上一页</a>
						<a href="javascript:page_next()" title="下一页" class="btn">下一页</a>
					</div>
				</div>

  
				<span class="f-r" style="position:absolute;top:3px;right:10px;">
				<span class="label label-success radius" onclick="sale(1)" style="cursor:pointer">刷新</span>
					 <span class="select-box inline" style="background:#fff;">
						<select name="brand_sale" class="select select_sale">
							<option value="0">所有品牌</option>
							<?php 		
							foreach(sku_tag_brand() as $val){
								$str = '';
								echo '<option value="'.$val.'" '.$str.'>'.$val.'</option>';
							}
							?>
						</select>
					</span>
					 <span class="select-box inline" style="background:#fff;">
						<select name="days_sale" class="select select_sale">
							<option value="1">昨日</option>
							<option value="3">3天</option>
							<option value="7">7天</option>
							<option value="30">30天</option>
						</select>
					</span>
					<input name="is_ys_checkbox_sale" type="checkbox" checked> 佑晟
				</span>
				
			</div>
		</div>
	</div>

</div>
<div id="notice" style="display:none;"><?php echo $notice;?></div>
<?php include $this->admin_tpl('footer', 'admin');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/echarts/echarts.min.js"></script>
<script type="text/javascript">
function yzm_clear_log(){
	layer.confirm('确认要清除错误日志吗？',function(index){
		$.ajax({
			type: 'GET',
			url: '<?php echo U('public_clear_log');?>', 
			dataType: "json", 
			success: function (msg) {
				if(msg.status == 1){
					layer.msg(msg.message, {icon:1,time: 800}, function(){
					  window.location.reload();     
					});
				}else{
					layer.msg(msg.message, {icon:2,time: 2500});
				}
			}
		})	
	});
	
}
function open_log(){
	let url = '<?php echo U('public_open_log')?>';
	layer.open({  
		type: 2,  
		title: '查看错误日志',  
		shadeClose: true,  
		shade: 0.2,  
		area: ['1000px', '800px'],  
		content: url,
		success: function(layero, index){
			
		}
	}) 
}



var page = 1;
var clear = 0;
var clear_sale = 0;
var myChart = echarts.init(document.getElementById('container'));
var myChart2 = echarts.init(document.getElementById('container2'));
var dom = document.getElementById('container');
var dom2 = document.getElementById('container2');
var myChart = echarts.init(dom, null, {
  renderer: 'canvas',
  useDirtyRect: false
});
var myChart2 = echarts.init(dom2, null, {
  renderer: 'canvas',
  useDirtyRect: false
});
echart();
echart2();
sale();
//缺货建议暂时取消
//suggest();
function setOption(res){
	$('#container').show();
	$('#loading').hide();
	let index = res.qty.length-1;
	if(index > 0){
		res.qty[index] = {value:res.qty[index],itemStyle:{color:'#FDD238'}};
	}
	myChart.setOption({
	  tooltip: {
		trigger: 'axis',
		axisPointer: {
		  type: 'shadow'
		}
	  },
	  grid: {
		left: '0%',
		right: '4%',
		bottom: '5%',
		containLabel: true
	  },
	  xAxis: [
		{
		  type: 'category',
		  data: res.date,
		  axisTick: {
			alignWithLabel: true
		  }
		}
	  ],
	  yAxis: [
		{
		  type: 'value',
		  show: false,
		}
	  ],
	  series: [
		{
		  name: '发货（件）',
		  type: 'bar',
		  barWidth: '60%',
		  data: res.qty,
		}
	  ]
	});
}
function setOption2(res){
	$('#container2').show();
	$('#loading2').hide();
	let qty3=[];
	res.qty1.map((item,index)=>{
		if(res.qty1[index+1]!==''){
			qty3.push('');
		}else{
			qty3.push({value:item,symbolSize:8})
		}
	});
	//console.log(qty3);
	myChart2.setOption({
	  tooltip: {
		trigger: 'axis',
		axisPointer:{
		  lineStyle:{
			width:2,
			color:'#54A0FF'
		  }
		}
	  },
	  legend: {
		data: ['今天（件）', '昨天（件）', '前天（件）']
	  },
	  grid: {
		left: '0%',
		right: '4%',
		bottom: '5%',
		containLabel: true
	  },
	  xAxis: [
		{
		  type: 'category',
		  data: res.date,
		  axisTick: {
			alignWithLabel: true
		  }
		}
	  ],
	  yAxis: [
		{
		  type: 'value',
		  show: false,
		}
	  ],
	  series: [
		{
		  name: '今天（件）',
		  type: 'line',
		  data: res.qty1,
		  smooth: true,
		  showSymbol: false,
		},
		{
		  name: '昨天（件）',
		  type: 'line',
		  data: res.qty2,
		  smooth: true,
		  showSymbol: false,
		  itemStyle:{
			  normal:{
				  lineStyle:{
					  width:2,
					  type:'dashed'
				  }
			  }
		  }
		},{
		  name: '前天（件）',
		  type: 'line',
		  data: res.qty3,
		  smooth: true,
		  showSymbol: false,
		  itemStyle:{
			  normal:{
				  lineStyle:{
					  width:2,
					  type:'dashed',
					  color:'#bbb',
				  }
			  }
		  }
		},{
		 type: 'effectScatter',
		 smooth: true,
		 tooltip: {show:false},
		 showSymbol: false,
		 coordinateSystem: 'cartesian2d',
		 data: qty3, //2d坐标系
		 symbolSize:0,
		 showEffectOn: 'render',
		 rippleEffect: {
			 brushType: 'stroke'
		 },
		 hoverAnimation: true,
		 itemStyle: {
			 normal: {
				 color: '#FDD238',
				 shadowBlur: 3,
				 shadowColor: '#fff'
			 }
		 },
		 zlevel: 1
		}
	  ]
	});
}
function echart(clear){
	$('#container').hide();
	$('#loading').show();
	let shop_id = $('select[name="shop_id"]').val();
	let days = $('select[name="days"]').val();
	let is_ys = $('input[name="is_ys_checkbox"]').is(':checked') ? 1 : 0;
	$.ajax({
		type: 'GET',
		url: "<?php echo U('public_trend');?>",
		data: {shop_id:shop_id,days:days,is_ys:is_ys,clear:clear},
		dataType: "json", 
		success: function (res) {
			setOption(res);
		}
	});
}
function echart2(){
	$('#container2').hide();
	$('#loading2').show();
	let shop_id = $('select[name="shop_id_orders"]').val();
	let is_ys = $('input[name="is_ys_checkbox_orders"]').is(':checked') ? 1 : 0;
	$.ajax({
		type: 'GET',
		url: "<?php echo U('public_orders');?>",
		data: {shop_id:shop_id,is_ys:is_ys},
		dataType: "json", 
		success: function (res) {
			setOption2(res);
			setTimeout("echart2()",300*1000);
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			echart2();
			//alert(XMLHttpRequest.status);
			//alert(XMLHttpRequest.readyState);
			//alert(textStatus);
		}
	});
}
function sale(clear_sale){
	$('#page').hide();
	$('#container_sale').hide();
	$('#loading_sale').show();
	let brand = $('select[name="brand_sale"]').val();
	let days = $('select[name="days_sale"]').val();
	let is_ys = $('input[name="is_ys_checkbox_sale"]').is(':checked') ? 1 : 0;
	$.ajax({
		type: 'GET',
		url: "<?php echo U('public_sale');?>",
		data: {brand:brand,days:days,page:page,is_ys:is_ys,clear:clear_sale},
		dataType: "html", 
		success: function (res) {
			$('#container_sale').html(res);
			layer.closeAll('loading');
			$('#page').show();
			$('#container_sale').show();
			$('#loading_sale').hide();
		}
	});
}

function suggest(clear_suggest){
	$('#container_suggest').hide();
	$('#loading_suggest').show();
	$.ajax({
		type: 'GET',
		url: "<?php echo U('public_suggest');?>",
		data: {},
		dataType: "html", 
		success: function (res) {
			$('#container_suggest').html(res);
			layer.closeAll('loading');
			$('#container_suggest').show();
			$('#loading_suggest').hide();
		}
	});
}

$('.select_trend').change(function(){
	if($(this).attr('name') == 'shop_id'){
		$('input[name="is_ys_checkbox"]').attr("checked", false);
	}
	echart();
})
$('.select_orders').change(function(){
	if($(this).attr('name') == 'shop_id_orders'){
		$('input[name="is_ys_checkbox_orders"]').attr("checked", false);
	}
	echart2();
})
$('.select_sale').change(function(){
	if($(this).attr('name') == 'brand_sale'){
		$('input[name="is_ys_checkbox_sale"]').attr("checked", false);
	}
	sale();
})

function page_prev(){
	if(page>1){
		page = page-1;
		sale();
	}else{
		layer.msg('已首页！');
	}
}
function page_next(){
	if(page<10){
		page = page+1;
		sale();
	}else{
		layer.msg('已是最后一页！');
	}
}
$('input[name="is_ys_checkbox"]').click(function(){
	$('select[name="shop_id"]').val("0");
	echart();
});

$('input[name="is_ys_checkbox_orders"]').click(function(){
	$('select[name="shop_id_orders"]').val("0");
	echart2();
});

$('input[name="is_ys_checkbox_sale"]').click(function(){
	$('select[name="brand_sale"]').val("0");
	sale();
});
//通知
if($('#notice').html()!=''){
	layer.open({
	  title: '重要通知',
	  content: $('#notice').html(),
	  area: ['600px', '500px'], 
	  success: function(layero, index){
		//open_tag('.btn_tag2');
	  }
	})
}

</script>
</body>
</html>